package cn.da.shuai.cool.ai.search.client.controller;

import cn.da.shuai.cool.ai.search.client.common.enums.SSEMsgType;
import cn.da.shuai.cool.ai.search.client.util.SSEServerUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/sse")
public class SseController {

    @GetMapping(value="/connect/{userId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter connect(@PathVariable String userId) {
        return SSEServerUtil.connect(userId);
    }

    @GetMapping(value="/send/{userId}/{message}")
    public void send(@PathVariable String userId, @PathVariable String message) {
        SSEServerUtil.send(userId, message, SSEMsgType.MESSAGE);
    }
}
